package dk.pun.aot.client.dice;

import java.util.Random;

public class DiceRoller {

	private static final Random random = new Random();
	
	public int rollDie(DieType die) {
		int roll = 0;
		switch(die) {
		case D4: roll = random.nextInt(4)+1; break;
		case D6: roll = random.nextInt(6)+1; break;
		case D8: roll = random.nextInt(8)+1; break;
		case D10: roll = random.nextInt(10)+1; break;
		case D12: roll = random.nextInt(12)+1; break;
		case D20: roll = random.nextInt(20)+1; break;
		}
		return roll;
	}

	public DiceRoll rollDicePool(String title, DicePoolType dicePoolType, int modifier, DiceRollType diceRollType) {
		String rolls = "";
		int result = modifier;
		for (int i=0; i<dicePoolType.getDieOneAmount(); i++) {
			int thisRoll = this.rollDie(dicePoolType.getDieOne());
			result += thisRoll;
			rolls = rolls.concat(String.valueOf(thisRoll) + ' ');
		}
		if (dicePoolType.hasTwoDiceSets()) {
			rolls = rolls.concat(", ");
			for (int i=0; i<dicePoolType.getDieTwoAmount(); i++) {
				int thisRoll = this.rollDie(dicePoolType.getDieTwo());
				result += thisRoll;
				rolls = rolls.concat(String.valueOf(thisRoll) + ' ');
			}
		}
		return new DiceRoll(title, dicePoolType, modifier, rolls.trim(), result, diceRollType);
	}
	
}
